{% extends "common/base.html" %}
{% block content %}

<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">用户列表</div>
                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success" id="useradd" ><span class="am-icon-plus"></span> 添加用户</button>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select data-am-selected="{btnSize: 'sm'}">
                                <option value="option1">账户</option>
                                <option value="option2">姓名</option>
                                <option value="option3">邮箱</option>
                                <option value="option3">电话</option>
                                <option value="option3">QQ</option>
                                <option value="option3">微信</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p ">
                            <input type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
                                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button" ></button>
                            </span>
                        </div>

                    </div>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-text-nowrap tpl-table-black " id="example-r">
                            <thead>
                                <tr>
                                    <th>账户</th>
                                    <th>姓名</th>
                                    <th>邮箱</th>
                                    <th>电话</th>
                                    <th>QQ</th>
                                    <th>微信</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for u in users %}
                                    <tr class="even gradeC">
                                        <td>{{ u.username }}</td>
                                        <td>{{ u.last_name }}{{ u.first_name }}</td>
                                        <td>{{ u.email }}</td>
                                        <td>{{ u.userprofile.phone }}</td>
                                        <td>{{ u.userprofile.qqnum }}</td>
                                        <td>{{ u.userprofile.weixin }}</td>
                                        <td>
                                            <div class="tpl-table-black-operation">
                                                <a href="/users/change/{{ u.id }}/">
                                                    <i class="am-icon-pencil"></i> 编辑
                                                </a>
                                                <a href="javascript:;" class="tpl-table-black-operation-del" onclick="userdel({{ u.id }})">
                                                    <i class="am-icon-trash"></i> 删除
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                        <div class="am-u-lg-12 am-cf">
                            <div class="am-fr">
                                <ul class="am-pagination tpl-pagination">
                                    <li class="am-disabled"><a href="#">«</a></li>
                                    <li class="am-active"><a href="#">1</a></li>
                                    <li><a href="#">2</a></li>
                                    <li><a href="#">3</a></li>
                                    <li><a href="#">4</a></li>
                                    <li><a href="#">5</a></li>
                                    <li><a href="#">»</a></li>
                                </ul>
                            </div>
                        </div>
                </div>
            </div>
        </div>
    </div>
</div>



<script>
    $(function() {
        $('#useradd').on('click', function() {
            $('#addmodal').modal({
            });
        });
    });
    
    function userdel(id) {
        $('#delmodail').modal({
            onConfirm: function(e) {
                    location.href="/users/del/"+id+"/";
                }
        });
    }
</script>
{% endblock %}
{% block modals %}
<div class="am-modal am-modal-prompt" tabindex="-1" id="addmodal">
    <div class="am-modal-dialog">
        <div class="am-modal-hd"><b>添加用户</b></div>
        <form action="/users/add/" class="am-form" method="post" data-am-validator>{% csrf_token %}
            <fieldset>
                <div class="am-form-group">
                    <label for="username">账户：</label>
                    <input type="text" id="username" name="username" minlength="3" placeholder="输入用户名" required/>
                </div>

                <div class="am-form-group">
                    <label for="last_name">姓：</label>
                    <input type="text" id="last_name" name="last_name"  placeholder="姓" required/>
                </div>

                <div class="am-form-group">
                    <label for="first_name">名：</label>
                    <input type="text" id="first_name" name="first_name" placeholder="名" required/>
                </div>

                <div class="am-form-group">
                    <label for="password">密码：</label>
                    <input type="password" id="password" name="password" minlength="8" placeholder="输入密码" required/>
                </div>
{#                <div class="am-form-group">#}
{#                    <label for="password2">重复密码：</label>#}
{#                    <input type="password" id="password2" name="password2" placeholder="重复密码"  data-equal-to="#password1" required/>#}
{#                </div>#}

                <div class="am-form-group">
                    <label for="email">邮箱：</label>
                    <input type="email" id="email" name="email" placeholder="输入邮箱" required/>
                </div>
            </fieldset>
            <div class="am-modal-footer">
                <span class="am-modal-btn" data-am-modal-cancel>取消</span>
{#                <span class="am-modal-btn" data-am-modal-confirm>提交</span>#}
                <button class="am-btn am-btn-secondary" type="submit">提交</button>
            </div>
        </form>

    </div>
</div>


<div class="am-modal am-modal-confirm" tabindex="-1" id="delmodail">
      <div class="am-modal-dialog">
            <div class="am-modal-hd">Duke 提醒</div>
            <div class="am-modal-bd">
              你，确定要删除吗？
            </div>
            <div class="am-modal-footer">
                  <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                  <span class="am-modal-btn" data-am-modal-confirm>确定</span>
            </div>
      </div>
</div>

{% endblock %}